﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

namespace BSPortal.Report
{
    public partial class ReportPage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            /*
            //Check admin right
            if (System.Web.HttpContext.Current.Session["UserType"] == null || (int)System.Web.HttpContext.Current.Session["UserType"] != (int)Common.UserType.ADMIN || Session["ExportData"] == null)
            {
                Response.Redirect("~/Default.aspx?Page=Login");
            }

            //var exportData = (List<Order>)Session["ExportData"];

            //Get list order id
            string orderids = "(";
            foreach (var item in exportData)
            {
                orderids += item.OrderId + ",";
            }
            orderids = orderids.Substring(0, orderids.Length - 1);
            orderids += ")";
            */
            //Create report
            var report = new rptOrder();
            using (SqlConnection connection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["OnlineShopConnectionString"].ConnectionString))
            {
                //Select order with conditions
                var command = new SqlCommand("SELECT * FROM [order]", connection);
                SqlDataAdapter adapter = new SqlDataAdapter(command);

                //Fill data into table
                DataTable table = new DataTable("order");
                adapter.FillSchema(table, SchemaType.Mapped);
                adapter.Fill(table);

                //Set report data and login infomation
                report.SetDataSource(table);
                report.SetDatabaseLogon("nh72hs9x_sa", "P@ssw0rd", "103.28.36.28", "nh72hs9x_onlineshop");                

                //Display report
                CrystalReportViewer1.ReportSource = report;
            }
        }
    }
}